package com.jic.member.controller.manage;

import com.jic.common.base.vo.PageResult;
import com.jic.common.base.vo.RestResult;
import com.jic.member.entity.TripEntity;
import com.jic.member.request.TripEntityIdRequest;
import com.jic.member.request.TripEntityQueryRequest;
import com.jic.member.request.TripEntityRequest;
import com.jic.member.response.TripEntityResponse;
import com.jic.member.response.TripInfoResponse;
import com.jic.member.service.TripService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 旅程主表
 * @author wwb
 */
@Slf4j
@Api(tags = "旅程主表")
@RestController
@RequestMapping("/trip")
public class TripController {

    @Resource
    private TripService tripService;

    @ApiOperation("新增/编辑旅程基本信息")
    @ResponseBody
    @PostMapping("/updateTrip")
    public RestResult<Long> updateTrip(@RequestBody TripEntityRequest tripEntity){
        return tripService.updateTrip(tripEntity);
    }

    @ApiOperation("确认保存旅程信息/保存为草稿")
    @ResponseBody
    @PostMapping("/confirmSaveOrDraft")
    public RestResult<Boolean> confirmSaveOrDraft(@RequestBody TripEntityIdRequest tripEntityIdRequest){
        return tripService.confirmSaveOrDraft(tripEntityIdRequest);
    }

    @ApiOperation("查看用户旅程列表")
    @ResponseBody
    @PostMapping("/queryTripList")
    public RestResult<PageResult<TripEntityResponse>> queryTripList(@RequestBody TripEntityQueryRequest tripEntityQueryRequest){
        try {
            PageResult<TripEntityResponse> pageResult = tripService.queryPage(tripEntityQueryRequest);
            return RestResult.success(pageResult);
        }catch (Exception e){
            log.error("crm tripList error：",e);
            return RestResult.error("9999","系统异常，列表查询失败");
        }

    }


    @ApiOperation("根据旅程Id查询基本信息和节点信息")
    @ResponseBody
    @PostMapping("/getTripDetailAndNodeList")
    public RestResult<TripInfoResponse> getTripDetailAndNodeList(@RequestBody TripEntityIdRequest tripEntityIdRequest){
        return tripService.getTripDetailAndNodeList(tripEntityIdRequest);
    }


    @ApiOperation("删除用户旅程")
    @ResponseBody
    @PostMapping("/deleteTripInfo")
    public RestResult<String> deleteTripInfo(@RequestBody TripEntity tripEntity){
        try {
            tripService.delete(tripEntity.getId());
            return RestResult.success("删除成功");
        }catch (Exception e){
            log.error("crm deleteTripInfo error：",e);
            return RestResult.error("9999","系统异常，删除失败");
        }

    }

    @ApiOperation("关闭用户旅程")
    @ResponseBody
    @PostMapping("/closeTripInfo")
    public RestResult<String> closeTripInfo(@RequestBody TripEntity tripEntity){
        try {
            tripService.updateStatus(tripEntity);
            return RestResult.success("删除成功");
        }catch (Exception e){
            log.error("crm deleteTripInfo error：",e);
            return RestResult.error("9999","系统异常，关闭失败");
        }

    }

}
